package com.lsa.letcode.the90.subsets2;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import com.lsa.helpers.Utils;

public class Subsets2Test {
	@Test
	public void test() throws Exception {
		Solution s = new Solution();
//		System.out.println(s.subsetsWithDup(new int[] { 1, 2, 2, 3, 3 }));
		// System.out.println(s.subsets(new int[] { }));
		// System.out.println(s.subsets(new int[] { 11, 22, 33 }));
		System.out.println(s.subsetsWithDup(new int[] { 1, 2, 2}));

		test(s,
				Arrays.asList(new ArrayList<Integer>(), Arrays.asList(1), Arrays.asList(1,2), Arrays.asList(1,2,3), Arrays.asList(1,3), Arrays.asList(2), Arrays.asList(2,3), Arrays.asList(3)), new int[] { 1, 2, 3 });

		test(s,
				Arrays.asList(new ArrayList<Integer>(),Arrays.asList(11), Arrays.asList(11,22), Arrays.asList(11,22,33), Arrays.asList(11,33), Arrays.asList(22), Arrays.asList(22,33), Arrays.asList(33)), new int[] { 11, 22, 33 });

		test(s, Arrays.asList((List<Integer>) new ArrayList<Integer>()),
				new int[] {});

		testValue(new int[] { 0 }, 0);
		testValue(new int[] { 1 }, 1);
		testValue(new int[] { 1, 0 }, 2);
		testValue(new int[] { 1, 1 }, 3);
		testValue(new int[] { 1, 0, 0, 1 }, 9);
		testValue(new int[] { 1, 1, 1, 1 }, 15);
		testValue(new int[] { 1, 1, 1, 1, 1 }, 31);
		testValue(Utils.create01IntArray1D("1011100101"), 741);
		testValue(Utils.create01IntArray1D("1010011011"), 667);
		
	}

	private void testValue(int[] arr, int expected) {
		long val = Solution.value(arr);
		assertEquals(expected, val);
	}

	private void test(Solution s, List<List<Integer>> expected, int[] input) {
		assertEquals(expected, s.subsetsWithDup(input));
	}
}
